package com.example.webapp.web.controller.user;

import java.util.List;

import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.example.webapp.hibernate.HibernateManager;

@Controller
@RequestMapping(value = "user/")
public class UserController {
	private HibernateManager hibernateManager;
	
	@RequestMapping(value = "listUsers.html")
	public String listUsers(Model model) {
		Session session = hibernateManager.createSession();
		session.beginTransaction();
		List<?> userList = session.createQuery("from User").list();
		
		model.addAttribute("userList", userList);
		
		return "user/listUsers";
	}
	
	@Required
	public void setHibernateManager(HibernateManager hibernateManager) {
		this.hibernateManager = hibernateManager;
	}
}
